import 'package:flutter/material.dart';

void main() {
  runApp(IndexPage());
}

class IndexPage extends StatefulWidget {
  const IndexPage({Key? key}) : super(key: key);
  @override
  _IndexPageState createState() => _IndexPageState();
}

class _IndexPageState extends State<IndexPage> {
  final pages = [HomePage(), DatePage(), MyPage()];
  var currentIndex;
  @override
  void initState() {
    super.initState();
    currentIndex = 0;
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
          appBar: currentIndex != 2
              ? AppBar(
                  title: Text("二级网监控平台"),
                  // centerTitle: true,
                  leading: new IconButton(
                    tooltip: 'Previous choice',
                    icon: const Icon(Icons.arrow_upward_outlined),
                    onPressed: () {},
                  ),
                  actions: <Widget>[
                    new IconButton(
                      icon: const Icon(Icons.menu),
                      tooltip: 'Next choice',
                      onPressed: () {
                        print(2);
                      },
                    ),
                  ],
                )
              : null,
          bottomNavigationBar: BottomNavigationBar(
            items: [
              BottomNavigationBarItem(
                backgroundColor: Colors.blue,
                icon: Icon(Icons.home),
                label: "设备",
              ),
              BottomNavigationBarItem(
                backgroundColor: Colors.blue,
                icon: Icon(Icons.message),
                label: "数据",
              ),
              BottomNavigationBarItem(
                backgroundColor: Colors.blue,
                icon: Icon(Icons.shopping_cart),
                label: "我的",
              ),
            ],
            currentIndex: currentIndex,
            type: BottomNavigationBarType.shifting,
            onTap: (index) {
              setState(() {
                currentIndex = index;
              });
            },
          ),
          body: pages[currentIndex]),
    );
  }
}

class HomePage extends StatelessWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        padding: EdgeInsets.all(10.0),
        child: Column(
          children: [
            Row(
              children: [
                Container(
                  child: Text("操作"),
                  height: 50,
                )
              ],
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Column(
                  children: [
                    Image.asset(
                      "static/imgs/01.png",
                      width: 40.0,
                    ),
                    Text("操作")
                  ],
                ),
                Column(
                  children: [
                    Image.asset(
                      "static/imgs/02.png",
                      width: 40.0,
                    ),
                    Text("故障信息")
                  ],
                ),
                Column(
                  children: [
                    Image.asset(
                      "static/imgs/03.png",
                      width: 40.0,
                    ),
                    Text("恢复出厂")
                  ],
                ),
                Column(
                  children: [
                    Image.asset(
                      "static/imgs/04.png",
                      width: 40.0,
                    ),
                    Text("设备管理")
                  ],
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }
}

class DatePage extends StatelessWidget {
  const DatePage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: DefaultTabController(
        length: 3,
        child: Scaffold(
          appBar: AppBar(
            backgroundColor: Colors.white,
            elevation: 0.5,
            title: Material(
              color: Colors.white,
              child: TabBar(
                //选中的颜色
                indicatorColor: Colors.blue,
                //未选中的颜色
                unselectedLabelColor:Colors.black, 
                //文字颜色
                labelColor: Colors.black,
                tabs: [
                  Tab(text:"数据1",),
                  Tab(text:"数据2",),
                  Tab(text:"数据3",),
                ],
              ),
            ),
          ),
          body: TabBarView(
            children: [
              Icon(Icons.directions_car),
              Icon(Icons.directions_transit),
              Icon(Icons.directions_bike),
             
            ],
          ),
        ),
      ),
    );
  }
}

class MyPage extends StatelessWidget {
  const MyPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Text("wode"),
    );
  }
}
